unit uFrmGrid;

interface

uses
  Windows, Forms, uFrmRoot, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxStyles, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, DB,
  cxDBData, dxSkinsdxBarPainter, cxClasses, dxBar, ExtCtrls, cxGridLevel,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  Classes, Controls, cxGrid, DBClient, ImgList, ActnList;

type
  TFrmGrid = class(TFrmRoot)
    grdbtblvwData: TcxGridDBTableView;
    grdlvlData: TcxGridLevel;
    grdData: TcxGrid;
    pnlTop: TPanel;
    dxbrmngr1: TdxBarManager;
    dxbrMenu: TdxBar;
    CdsData: TClientDataSet;
    DsData: TDataSource;
    btnNew: TdxBarButton;
    btnEdit: TdxBarButton;
    btnDelete: TdxBarButton;
    btnFilter: TdxBarButton;
    btnPreview: TdxBarButton;
    btnPrint: TdxBarButton;
    dxbrpmn1: TdxBarPopupMenu;
    actlst1: TActionList;
    actNew: TAction;
    actEdit: TAction;
    actDelete: TAction;
    actFilter: TAction;
    actExp: TAction;
    actImp: TAction;
    actPreview: TAction;
    actPrint: TAction;
    btnShowGroup: TdxBarButton;
    btnShowFilter: TdxBarButton;
    actShowGroup: TAction;
    actShowFilter: TAction;
    BtnRefresh: TdxBarButton;
    BtnExport: TdxBarButton;
    actRefresh: TAction;
    BtnAutoWidth: TdxBarButton;
    BtnAutoHeight: TdxBarButton;
    actAutoWidth: TAction;
    actAutoHeight: TAction;
    procedure actlst1Update(Action: TBasicAction; var Handled: Boolean);
    procedure actShowGroupExecute(Sender: TObject);
    procedure actShowFilterExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure actAutoWidthExecute(Sender: TObject);
    procedure actAutoHeightExecute(Sender: TObject);
  private
    procedure SetDataRowHeight(AutoHeight: Boolean = False);
  public
    { Public declarations }
  end;

var
  FrmGrid: TFrmGrid;

implementation

uses UDmImage;

{$R *.dfm}

procedure TFrmGrid.actShowGroupExecute(Sender: TObject);
begin
  grdbtblvwData.OptionsView.GroupByBox :=
    not grdbtblvwData.OptionsView.GroupByBox;
end;

procedure TFrmGrid.actAutoHeightExecute(Sender: TObject);
begin
  inherited;
  grdbtblvwData.OptionsView.CellAutoHeight :=
    not grdbtblvwData.OptionsView.CellAutoHeight;
  SetDataRowHeight(grdbtblvwData.OptionsView.CellAutoHeight);
end;

procedure TFrmGrid.actAutoWidthExecute(Sender: TObject);
begin
  inherited;
  grdbtblvwData.OptionsView.ColumnAutoWidth :=
    not grdbtblvwData.OptionsView.ColumnAutoWidth;
end;

procedure TFrmGrid.actlst1Update(Action: TBasicAction; var Handled: Boolean);
var
  lHasData: Boolean;
begin
  inherited;
  actNew.Enabled := cdsData.Active;
  lHasData := cdsData.Active and not cdsData.IsEmpty;
  actEdit.Enabled := lHasData;
  actDelete.Enabled := lHasData;
  actExp.Enabled := lHasData;
end;

procedure TFrmGrid.actShowFilterExecute(Sender: TObject);
begin
  grdbtblvwData.OptionsCustomize.ColumnFiltering :=
    not grdbtblvwData.OptionsCustomize.ColumnFiltering;
end;

procedure TFrmGrid.FormCreate(Sender: TObject);
begin
  inherited;
  actShowGroup.Checked := grdbtblvwData.OptionsView.GroupByBox;
  actShowFilter.Checked := grdbtblvwData.OptionsCustomize.ColumnFiltering;
  actAutoWidth.Checked := grdbtblvwData.OptionsView.ColumnAutoWidth;
  actAutoHeight.Checked := grdbtblvwData.OptionsView.CellAutoHeight;
  SetDataRowHeight(actAutoHeight.Checked);
end;

procedure TFrmGrid.SetDataRowHeight(AutoHeight: Boolean);
begin
  if AutoHeight then
    grdbtblvwData.OptionsView.DataRowHeight := 0
  else
    grdbtblvwData.OptionsView.DataRowHeight := 24;
end;

end.
